<template>
	<view class="login-container">
		<!-- 状态栏占位 -->
		<view class="status-bar"></view>
		<!-- 品牌Logo区域 -->
		<view class="logo-section">
			<image src="/static/images/logo.png" mode="aspectFit"></image>
		</view>

		<!-- 主标题 -->
		<view class="main-title">
			<text>鲜链集配自助打印系统</text>
		</view>

		<!-- 输入框区域 -->
		<view class="input-section">
			<view class="input-group">
				<input class="input-field" type="text" placeholder="手机号" v-model="form.phoneNumber" />
			</view>
			<view class="input-group">
				<input class="input-field" :type="showPassword ? 'text' : 'password'" placeholder="密码" v-model="form.password" />
				<view class="password-toggle" @click="togglePassword">
					<text class="eye-icon">{{ showPassword ? '👁️' : '👁️‍🗨️' }}</text>
				</view>
			</view>
		</view>

		<!-- 用户协议 -->
		<view class="agreement-section">
			<view class="agreement-checkbox" @click="toggleAgreement">
				<view class="checkbox" :class="{ checked: agreedToTerms }">
					<text v-if="agreedToTerms" class="checkmark">✓</text>
				</view>
				<text class="agreement-text">阅读并同意</text>
				<text class="agreement-link" @click.stop="openPages('用户协议')">《用户协议》</text>
				<text class="agreement-text">和</text>
				<text class="agreement-link" @click.stop="openPages('隐私政策')">《隐私政策》</text>
			</view>
		</view>

		<!-- 登录按钮 -->
		<view class="login-button-section">
			<button class="login-button" @click="handleLogin">立即登录</button>
		</view>

		<!-- 底部选项 -->
		<view class="bottom-options">
			<view class="remember-password" @click="toggleRememberPassword">
				<view class="checkbox" :class="{ checked: rememberPassword }">
					<text v-if="rememberPassword" class="checkmark">✓</text>
				</view>
				<text class="option-text">记住密码</text>
			</view>
			<text class="forgot-password" @click="handleForgotPassword">找回密码</text>
		</view>

		<!-- 更多选项分隔线 -->
		<view class="more-divider">
			<view class="divider-line"></view>
			<text class="divider-text">更多</text>
			<view class="divider-line"></view>
		</view>

		<!-- 短信登录 -->
		<view class="sms-login" @click="handleSmsLogin">
			<text class="sms-icon">📱</text>
			<text class="sms-text">短信验证码登录</text>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			form: {},
			showPassword: false,
			agreedToTerms: false,
			rememberPassword: false
		};
	},
	onShow() {
		let savePass = uni.getStorageSync('savePass');
		this.form = savePass || {};
		this.rememberPassword = !!savePass;
	},
	methods: {
		togglePassword() {
			this.showPassword = !this.showPassword;
		},
		toggleAgreement() {
			this.agreedToTerms = !this.agreedToTerms;
		},
		toggleRememberPassword() {
			this.rememberPassword = !this.rememberPassword;
			this.setSavePass();
		},
		
		setSavePass(){
			if (this.rememberPassword) {
				uni.setStorageSync('savePass', this.form);
			} else {
				uni.removeStorageSync('savePass');
			}
		},
		openPages(title) {
			this.toNav(`agreement/agreement?title=${title}`);
		},
		handleLogin() {
			if (!this.form.phoneNumber) {
				uni.showToast({
					title: '请输入手机号',
					icon: 'none'
				});
				return;
			}
			if (!this.form.password) {
				uni.showToast({
					title: '请输入密码',
					icon: 'none'
				});
				return;
			}
			if (!this.agreedToTerms) {
				uni.showToast({
					title: '请先同意用户协议和隐私政策',
					icon: 'none'
				});
				return;
			}
			this.setSavePass();
			uni.showToast({
				title: '登录成功',
				icon: 'success'
			});
			this.toNav('index/index')
		},
		handleForgotPassword() {
			uni.showToast({
				title: '找回密码功能',
				icon: 'none'
			});
		},
		handleSmsLogin() {
			uni.showToast({
				title: '短信验证码登录',
				icon: 'none'
			});
		}
	}
};
</script>

<style lang="scss">
.login-container {
	min-height: 100vh;
	background: linear-gradient(180deg, #e3f2fd 0%, #ffffff 100%);
	position: relative;
	font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

.status-bar {
	height: 44px;
	background: transparent;
}

.logo-section {
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
	padding: 40rpx 0 60rpx;
	image {
		width: 200rpx;
		height: 200rpx;
		filter: drop-shadow(5px 10px 10px rgba(0, 0, 0, 0.3));
	}
}

.brand-text {
	text-align: center;
}

.brand-name {
	font-size: 32rpx;
	font-weight: bold;
	color: #1976d2;
	display: block;
	margin-bottom: 8rpx;
}

.brand-subtitle {
	font-size: 24rpx;
	color: #1976d2;
	display: block;
}

.main-title {
	text-align: center;
	margin-bottom: 80rpx;
}

.main-title text {
	font-size: 36rpx;
	font-weight: bold;
	color: #333333;
}

.input-section {
	padding: 0 60rpx;
	margin-bottom: 40rpx;
}

.input-group {
	position: relative;
	margin-bottom: 30rpx;
}

.input-field {
	width: 100%;
	height: 88rpx;
	background: #ffffff;
	border: 2rpx solid #e0e0e0;
	border-radius: 12rpx;
	padding: 0 30rpx;
	font-size: 28rpx;
	color: #333333;
	box-sizing: border-box;
	box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
}

.input-field:focus {
	border-color: #1976d2;
	outline: none;
}

.input-field::placeholder {
	color: #999999;
}

.password-toggle {
	position: absolute;
	right: 30rpx;
	top: 50%;
	transform: translateY(-50%);
	width: 40rpx;
	height: 40rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.eye-icon {
	font-size: 32rpx;
	color: #666666;
}

.agreement-section {
	padding: 0 60rpx;
	margin-bottom: 60rpx;
}

.agreement-checkbox {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
}

.checkbox {
	width: 32rpx;
	height: 32rpx;
	border: 2rpx solid #1976d2;
	border-radius: 6rpx;
	margin-right: 16rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	background: #ffffff;
	transition: all 0.3s ease;
}

.checkbox.checked {
	background: #1976d2;
	box-shadow: 0 2rpx 8rpx rgba(25, 118, 210, 0.3);
}

.checkmark {
	color: #ffffff;
	font-size: 20rpx;
	font-weight: bold;
}

.agreement-text {
	font-size: 24rpx;
	color: #333333;
	margin-right: 8rpx;
}

.agreement-link {
	font-size: 24rpx;
	color: #1976d2;
	text-decoration: underline;
	margin: 0 4rpx;
	transition: opacity 0.3s ease;
}

.agreement-link:active {
	opacity: 0.7;
}

.login-button-section {
	padding: 0 60rpx;
	margin-bottom: 60rpx;
}

.login-button {
	width: 100%;
	height: 88rpx;
	background: #1976d2;
	color: #ffffff;
	border: none;
	border-radius: 12rpx;
	font-size: 32rpx;
	font-weight: bold;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 4rpx 12rpx rgba(25, 118, 210, 0.3);
	transition: all 0.3s ease;
}

.login-button:active {
	opacity: 0.8;
	transform: translateY(2rpx);
	box-shadow: 0 2rpx 8rpx rgba(25, 118, 210, 0.3);
}

.bottom-options {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 0 60rpx;
	margin-bottom: 40rpx;
}

.remember-password {
	display: flex;
	align-items: center;
}

.option-text {
	font-size: 24rpx;
	color: #333333;
	// margin-left: 16rpx;
}

.forgot-password {
	font-size: 24rpx;
	color: #1976d2;
	transition: opacity 0.3s ease;
}

.forgot-password:active {
	opacity: 0.7;
}

.more-divider {
	display: flex;
	align-items: center;
	padding: 0 60rpx;
	margin-bottom: 40rpx;
}

.divider-line {
	flex: 1;
	height: 2rpx;
	background: #e0e0e0;
}

.divider-text {
	font-size: 24rpx;
	color: #666666;
	margin: 0 30rpx;
}

.sms-login {
	display: flex;
	flex-direction: column;
	align-items: center;
	padding: 0 60rpx;
	transition: opacity 0.3s ease;
}

.sms-login:active {
	opacity: 0.7;
}

.sms-icon {
	font-size: 48rpx;
	margin-bottom: 16rpx;
}

.sms-text {
	font-size: 24rpx;
	color: #333333;
}
</style>
